package com.diu.domain.strategy.model.entity;

import com.diu.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author diu
 * @description 策略规则实体
 * @create_time 2025/10/4 12:44
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StrategyRuleEntity {
    private Long strategyId;
    private String ruleModel;
    private String ruleValue;

    public Map<String, List<Integer>> getRuleValueMap(){
        Map<String, List<Integer>> ruleValueMap = new HashMap<String, List<Integer>>();
        for(String ruleValue : ruleValue.split(Constants.SPACE)){
            String[] ruleValueArray = ruleValue.split(Constants.COLON);
            List<Integer> ruleValueList = new ArrayList<Integer>();
            for(String str : ruleValueArray[1].split(Constants.SPLIT)){
                ruleValueList.add(Integer.parseInt(str));
            }
            ruleValueMap.put(strategyId+"_"+ruleValueArray[0], ruleValueList);
        }
        return ruleValueMap;
    }
}
